﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Domain.DTO;
using Warehouse.Read.API.Applcation.Command.BeginFinalCommand;
using Warehouse.Read.API.Applcation.Command.InjureCommand;
using Warehouse.Read.API.Dtos;

namespace Warehouse.Read.API.Controllers
{
    /// <summary>
    /// 期初期末
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class BeginFinalController : ControllerBase
    {
        IMediator mediator;

        public BeginFinalController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 期初期末
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<BeginFinalDto>>> GetStoreList([FromQuery] BeginFinalListCommand command)
        {
            Dtos.ApiResult<PageDTO<BeginFinalDto>> result = new Dtos.ApiResult<PageDTO<BeginFinalDto>>();

            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }

    }
}
